<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<!--数据列表插件结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
	.plImport {
		background-color:#0C0;
		background-image: linear-gradient(to bottom, #0C0 0px, #090 100%);
		color: #FFFFFF;
		cursor: pointer;
		display: inline-block;
		padding: 2px 7px;
	}
	.import{
		margin:3px 10px 0px 0px;
	}
</style>
</head>
<body>
	<div class="page_header">
		<div class="table_tool">
			<ul class="clearfix">
				<php>if($_GET['order']){</php>
					<li class=" btn" id="addcart"><i class="icon-plus"></i>加入购物车</li>
				<php>}elseif($_GET['editorder']){</php>
					<li class=" btn" id="addorder"><i class="icon-plus"></i>加入订单</li>
				<php>}else{</php>
					<li class="memberDel btn"><i class="icon-remove"></i> 批量删除</li>
					<li class="line"></li>
					<li class="btn"><i class="icon-share-alt"></i>上下架操作
						<ul class="submenu">
							<li class="is_xiajia" rel="2">批量上架</li>
							<li class="is_xiajia" rel="1">批量下架</li>
						</ul>
					</li>
					<li class="line"></li>
					<li class="openwin btn" etitle="新增菜品" eheight="500px" ewidth="1100px" ehref="{:U('Product/add')}" id="Product_add"><i class="icon-plus"></i> 新增菜品</li>
					<li class="line"></li>
					<li class="openwin btn" etitle="菜品分类管理" eheight="300px" ewidth="650px" ehref="{:U('Product/sort')}" id="Product_sort"><i class="icon-list"></i> 菜品分类管理</li>
					<li class="line"></li>
					<li class="btn fuzhi"><i class="icon-list"></i> 批量复制属性</li>
					<li class="import" style="float:right"><span id="plImport" class="plImport">批量导入菜品</span></li>			
				<php>}</php>
			</ul>
		</div>
		<div class="search_box">
			<select name="restid" id="restid" class="form_ele form_ele_select" style="width:280px;">
				<option value="">请选择餐厅名称</option>
				<volist name="list" id="vo">
					<option value="{$vo.id}">{$vo.title}（{$vo.entitle|stripslashes=###}）</option>
				</volist>
			</select>
			<select name="sortid" id="sortid" class="form_ele w_100" style="width:280px;">
				<option value="">请选择菜品分类</option>
				<volist name='node' id='v'>
					<option value="{$v.id}">{$v.title}</option>
				</volist>
			</select>
			<select name="is_xiajia" id="is_xiajia" class="form_ele w_100">
				<option value="">请选择是否下架</option>
				<option value="1">是</option>
				<option value="2" selected>否</option>
			</select>
			<!--所属菜系：
			<select name="cuisineid" id="cuisineid" class="form_ele">
				<option value="">请选择</option>
				<volist name="cuisine" id="vo">
					<option value="{$key}">{$vo[0]}</option>
				</volist>
			</select>-->
			<input type="text" name="keywords" id="keywords" placeholder="请输入关键词" class="form_ele form_ele_text"/>
			<span class="doSearch" id="doSearch">
				<i class="icon-search"></i> 搜索
			</span>
			<span class="doSearch" id="doRest">重置搜索条件</span>
		</div>
	</div>
	<div class="table_box">
	</div>
</body>
<script type="text/javascript">
	var listConfig = {
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			jsonUrl : '__URL__/index&id={$id}',
			where : '',
			getWhere : function(){
				return getwheres();
			},
			showPageNav: false,
			widthType : 'tdw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : <php>if($_GET['order']||$_GET['editorder']){echo 999;}else{echo 10;}</php>,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			showPageNav: true,         //是否显示分页
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"edit": {
							name: "修改", 
							icon: "edit",
							callback: function(key, options) {
								var href     = "{:U('Product/edit')}&id="+$(this).attr('rowid');
								var width    = '1100px';
								var height   = '500px';
								var title    = '修改菜品';
								openDialog('Product_edit',href,width,height,title);
							}
						},
						"delete": {
							name: "删除", 
							icon: "del",
							callback: function(key, options) {
								var id = $(this).attr('rowid');
								$.get("{:U('Product/del')}",{ id: id },function(data){
									if(data.status==1){
										windowApi.lhgdialog.tips('数据删除成功！');
										$('.et_tfoot .page_refresh').click(); //刷新加载
									}else{
										windowApi.lhgdialog.tips(data.info);
									}
								});
							}
						}
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : true,
					myclass : 'center',
					width   : '20px',
					edit : false
				},
				{
					display : '所属餐厅',
					name : 'rtitle',
					sortable : true,
					myclass : 'center',
					width   : '120px',
					edit : false
				},
				{
					display : '菜品中文名称',
					name : 'title',
					sortable : true,
					myclass : 'center',
					edit : false,
					width: '130px'
				},
				{
					display : '菜品英文名称',
					name : 'entitle',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '菜品编号',
					name : 'dishes_num',
					sortable : true,
					myclass : 'center',
					edit : true,
					width:'100px'
				},
				{
					display : '零售价格',
					name : 'sprice',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : true
				},
				{
					display : '成本价格',
					name : 'mprice',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : true
				},
				{
					display : '菜品特价',
					name : 'tprice',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : true
				},
				{
					display : '是否下架',
					name : 'is_xiajia',
					sortable : true,
					myclass : 'center',
					width   : '100px',
					edit : false
				}
			]
		};
	
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	$(function(){
		
		//默认选中某个餐厅
		var id = "{$Think.get.id}";
		if(id){
			$("#restid").val(id);
		}
		
		//如果是修改订单，那么就不能选择餐厅
		<php>if($_GET['editorder']){</php>
			$('#restid').prop('disabled',true);
		<php>}</php>
		
		//批量导入菜品
		$('#plImport').live('click',function(){
			
			var restid = $('#restid').val();
			if(restid){
				var href = "{:U('Product/import')}&restid="+restid
				var width = '800px';
				var height = '400px';
				var title = '批量导入菜品';
				openDialog('Product_import',href,width,height,title);
			}else{
				windowApi.lhgdialog.alert('必须选择一个餐厅',function(){return;});
			}
		});
		
		//商品批量上下架
		$(".is_xiajia").each(function(){
			
			$(this).on("click",function(){
				var sxj = $(this).attr("rel");
				var val = tableList.getChecked();
				if(val){
					$.get("{:U('Product/is_xsj')}",{val:val,sxj:sxj},function(data){
						if(data.status==1){
							$('.chk_all').prop("checked",false);
							$('.et_tfoot .page_refresh').click(); //刷新加载
						}else{
							windowApi.lhgdialog.alert(data.info,function(){return;});
						}
					},'json');
				}else{
					windowApi.lhgdialog.alert('您还没有选择任何菜品！');
				}
				
			});
		});
		
		//批量复制商品属性
		$('.fuzhi').on('click',function(){
			
			var val    = tableList.getChecked();
			var restid = $('#restid').val();
			
			if(val){
				var href   = "{:U('Product/fuzhi')}&val="+val+"&restid="+restid;
				var width  = '420px';
				var height = '150px';
				var title  = '批量复制属性';
				openDialog('Order_deal',href,width,height,title);
			}else{
				windowApi.lhgdialog.alert('您还没有选择任何菜品！');
			}
		});
		
		//将选中的商品添加到购物车
		$('#addcart').on('click',function(){
			var outletid = "{$Think.get.id}";
			var cityid   = "{$Think.get.cityid}";
			var val      = tableList.getChecked();
			var flag     = 'dishes';
			if(val){
				
				$.get("{:U('Order/addcart')}",{val:val,outletid:outletid,cityid:cityid,flag:flag},function(data){
					if(data.status==1){
						//添加到购物车之后的操作
						var api = frameElement.api;
						var obj = api.get('Order_add');
						obj.document.getElementById('clickproduct').click();
						windowApi.lhgdialog.tips('加入购物车成功');

						$('.chk_item').each(function(){
							$(this).prop('checked',false);
							$(this).parents('tr').removeClass('select');
						});
						//$('.et_tfoot .page_refresh').click(); //刷新加载
						//frameApi.close(); //关闭当前窗口
					}else{
						windowApi.lhgdialog.alert(data.info);
					}
				});
			}else{
				windowApi.lhgdialog.alert('您还没有选择任何菜品！');
			}
		});
		
		//将选中的商品添加到订单
		$('#addorder').on('click',function(){
			var outletid = "{$Think.get.id}";
			var orderno  = "{$Think.get.orderno}";
			var val      = tableList.getChecked();
			var flag     = 'dishes';
			if(val){
				
				$.post("{:U('Order/edit')}",{val:val,flag:flag,orderno:orderno,adddetail:'1'},function(data){
					if(data.status==1){
						//添加到购物车之后的操作
						var api = frameElement.api;
						var obj = windowApi.lhgdialog.list['Order_edit'];
						
						obj.reload(obj);
						windowApi.lhgdialog.alert('加入订单成功');
						//frameApi.close(); //关闭当前窗口
					}else{
						windowApi.lhgdialog.alert(data.info);
					}
				});
			}else{
				windowApi.lhgdialog.alert('您还没有选择任何菜品！');
			}
		});
		
		//根据餐厅筛选菜品分类
		$('#restid').on('change',function(){
			var restid = $('#restid').val();
			$.get("{:U('Product/sort')}",{restid:restid},function(data){
				$('#sortid').html(data);
			})
		});
		
		//根据菜系筛选
		$('#cuisineid>option').each(function(){
			$(this).on('click',function(){
				byCondition();
			});
		});
		
		//根据是否推荐筛选
		$('#isrecommend>option').each(function(){
			$(this).on('click',function(){
				byCondition();
			});
		});
		
		//根据品牌类型筛选
		$('#type>option').each(function(){
			$(this).on('click',function(){
				byCondition();
			});
		});
		
		//批量删除
		$('.memberDel').on('click',function(){
			
			var val = tableList.getChecked();
			var msg = "确认要将选中的菜品删除吗？";
			if(val){
				windowApi.lhgdialog.confirm(msg, function(){
					$.post("{:U('Product/delall')}",{val:val},function(data){
						if(data.status==1){
							$('.et_tfoot .page_refresh').click(); //刷新加载
						}else{
							windowApi.lhgdialog.alert(data.info,function(){return;});
						}
					});
				},function(){return;});
			}else{
				windowApi.lhgdialog.alert('请选择需要删除的菜品！');
			}
		});
		
	});
	
	//获取筛选条件并组成数组
	function getwheres(){
		
		var where  = {};
		where.restid         = $('#restid').val();
		where.is_xiajia      = $('#is_xiajia').val();
		where.keywords       = $('#keywords').val();
		where.sortid         = $('#sortid').val();
		return where;
	}
	
	//搜索
 	$('#doSearch').on('click',function(){
		byCondition();
	});

	//重置搜索条件
	$('#doRest').on('click',function(){
		$('#restid').val("");
		$('#is_xiajia').val("");
		$('#keywords').val("");
		$('#sortid').val("");
	});
	
	//发送异步进行搜索
	function byCondition(){
		var where = tableList.config.getWhere();
		
		tableList.config.nowPage = 1;
		tableList.config.where   = where;
		tableList.search();
	}
	//tableList.erefresh();
</script>
</html>
